package component
{
	import events.CommonEvent;
	import flash.events.Event;
	import spark.components.CheckBox;
	import spark.components.supportClasses.ItemRenderer;
	
	public class CheckListItemRender extends ItemRenderer
	{
		protected var checkbox:CheckBox;
		override protected function createChildren():void
		{
			super.createChildren();
			checkbox = new CheckBox();
			checkbox.top = 2;
			checkbox.left = 5;
			checkbox.addEventListener("change",chkData_changeHandler);
			this.addElement(checkbox);
		}
		
		override public function set data( value:Object ) : void {
			super.data = value;
			if(data != null){
				var labefield:String = (this.owner as CheckList).labelField;
				checkbox.label = data[labefield];
				checkbox.selected = data.selected;
			}
		}
		
		protected function chkData_changeHandler(event:Event):void
		{
			if(data != null){
				data.selected = checkbox.selected;
				var objEvent:CommonEvent = new CommonEvent("CheckChanged",data);
				(this.owner as CheckList).dispatchEvent(objEvent);
			}
		}
	}
}